// Code scaffolded by goctl. Safe to edit.
// goctl 1.9.1

package fileTag

import (
	"audio-server/internal/model"
	"audio-server/internal/sqlutil"
	"context"
	"errors"

	"audio-server/internal/svc"
	"audio-server/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type FileTagAllListLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewFileTagAllListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *FileTagAllListLogic {
	return &FileTagAllListLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *FileTagAllListLogic) FileTagAllList() (resp []types.FileTagRes, err error) {
	id := sqlutil.GetUserId(l.ctx)
	if id == 0 {
		return nil, errors.New("请先登录")
	}
	tagModel := model.NewSysFileTagModel(l.svcCtx.Conn)
	list, err := tagModel.FindList(l.ctx, id)
	if err != nil {
		return nil, err
	}

	var result []types.FileTagRes
	for _, tag := range list {
		result = append(result, types.FileTagRes{
			TagId: tag.TagId,
			Title: tag.Title,
		})
	}
	return result, nil
}
